<template>
	<view class="check-container">
		<tab-nav :tabCurrentIndex="tabCurrentIndex" :navList="navList" @change="setTabIndex"></tab-nav>
		<view class="search">
			<view class="search-box">
				<view class="icon">
					<image src="../../static/search.png"></image>
				</view>
				<input  v-model="searchText" type="text" @confirm="handleSearch" confirm-type="search" class="search-input"
				 placeholder="请输入检查点名称">
				<!-- <view v-if="isFocus" @click="resetSearch" class="clear-icon">x</view> -->
				<dean-popover modalLeftPos="-90rpx" :active="active" @select="selectChange" ref="deanPopover" class="pop" :btnList="btnList"></dean-popover>
			</view>
		</view>
		<check-item @detail="goCheck" v-if="tabCurrentIndex === 0 && planList" :check-list="planList"></check-item>
		<view v-else-if="tabCurrentIndex === 0 && !planList">
			<van-empty description="暂无巡检单" />
		</view>
		<uni-load-more v-if="tabCurrentIndex === 0 && planList && planList.length >= 10" :status="status" />
		<check-item @detail="goCheck" v-if="tabCurrentIndex === 1 && dailyList" :check-list="dailyList"></check-item>
		<view v-else-if="tabCurrentIndex === 1 && !dailyList">
			<van-empty description="暂无巡检单" />
		</view>
		<uni-load-more v-if="tabCurrentIndex === 1 && dailyList && dailyList.length >= 10" :status="status1" />
	</view>
</template>

<script>
	import TabNav from '@/fireGridCheck/components/tab-nav/tab-nav.vue'
	import DeanPopover from '@/fireGridCheck/components/dean-popover/dean-popover.vue'
	import CheckItem from '@/fireGridCheck/components/checkItem.vue'
	export default {
		components: {
			TabNav,
			DeanPopover,
			CheckItem
		},
		data() {
			return {
				status: 'more',
				status1: 'more',
				searchText: '',
				planList: [],
				dailyList: [],
				params: {
					巡检类型: 1,
					所属网格id: null,
					网格员id: null,
					巡检状态: 1,
					pagination: {
						current: 1,
						pageSize: 10
					},
					sorter: {
						field: "巡检优先级",
						order: 0
					}
				},
				params1: {
					巡检类型: 2,
					所属网格id: null,
					网格员id: null,
					巡检状态: 1,
					pagination: {
						current: 1,
						pageSize: 10
					},
					sorter: {
						field: "巡检优先级",
						order: 0
					}
				},
				planTotal: 0,
				dailyTotal: 0,
				tabCurrentIndex: 0,
				navList: [{
						text: '计划巡检单',
						total: 0
					},
					{
						text: '日常巡检单',
						total: 0
					}
				],
				btnList: ['全部', '企业单位','住宅小区','餐饮店','个体诊所','商铺'],
				btnTypeList: [null,'company','residential','restaurant','clinic','shop']
			}
		},
		onLoad() {
			this.params.所属网格id = uni.getStorageSync('gridInfo').所属网格id
			// this.params.网格员id = uni.getStorageSync('userInfo').id
			this.params1.所属网格id = uni.getStorageSync('gridInfo').所属网格id
			// this.params1.网格员id = uni.getStorageSync('userInfo').id
		},
		onReachBottom() {
			console.log('触发上拉')
			if(this.tabCurrentIndex == 0 && this.status !== 'noMore' && this.planList) {
				this.status = 'loading'
				this.getMorePlanTask()
			}
			if(this.tabCurrentIndex == 1 && this.status1 !== 'noMore' && this.dailyList) {
				this.status1 = 'loading'
				this.getMoreDailyTask()
			}
		},
		onShow() {
			this.getPlanTask()
			this.getDailyTask()
		},
		watch: {
			searchText() {
				if(this.searchText == '') {
					this.initName('')
			
				}
			}
		},
		methods: {
			goCheck(item) {
				uni.navigateTo({
					url: '/fireGridCheck/checkList/checkList?item=' + JSON.stringify(item)
				})
			},
			initName(params) {
				this.params.检查点名称 = params
				this.params1.检查点名称 = params
				this.getPlanTask()
				this.getDailyTask()
			},
			initType(params) {
				this.params.检查点类型 = params
				this.params1.检查点类型 = params
				this.getPlanTask()
				this.getDailyTask()
			},
			selectChange(val) {
				console.log(val)
				this.initType(this.btnTypeList[val])
			},
			handleSearch() {
				this.initName(this.searchText)
			},
			setTabIndex(val) {
				this.tabCurrentIndex = val
			},
			getPlanTask() {
				this.params.pagination.current = 1
				this.$http.post('gridSystem/inspection/list', this.params).then(res => {
					if(res.code === 10000){
						console.log(res)
						this.planList = res.data.list
						this.navList[0].total = res.data.total
					}
				})
			},
			getMorePlanTask() {
				this.params.pagination.current++
				this.$http.post('gridSystem/inspection/list', this.params).then(res => {
					if(res.code === 10000){
						if(res.data.list !== null) {
							this.planList = [...this.planList, ...res.data.list]
						}
						if(this.planList.length === res.data.total){
							this.status = 'noMore'
						}
					}
				})
			},
			getDailyTask() {
				this.params.pagination.current = 1
				this.$http.post('gridSystem/inspection/list', this.params1).then(res => {
					if(res.code === 10000){
						console.log(res)
						this.dailyList = res.data.list
						this.navList[1].total = res.data.total
					}
				})
			},
			getMoreDailyTask() {
				this.params.pagination.current++
				this.$http.post('gridSystem/inspection/list', this.params1).then(res => {
					if(res.code === 10000){
						if(res.data.list !== null) {
							this.dailyList = [...this.dailyList, ...res.data.list]
						}
						if(this.dailyList.length === res.data.total){
							this.status1 = 'noMore'
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.check-container {
		padding-top: 66rpx;
	}
	.search {
		// margin-left: 100rpx;
		padding-left: 60rpx;
		width: 750rpx;
		height: 96rpx;
		margin-bottom: 20rpx;
		background-color: #fff;
		display: flex;
		border: 2rpx solid #f5f5f5;
		align-items: center;
		// justify-content: center;
		position: relative;
		// padding-left: 50rpx;
		.search-box {
			width: 564rpx;
			height: 56rpx;
			padding-left: 17rpx;
			padding-right: 10rpx;
			color: #999;
			// background-color: pink;
			border: 2rpx solid #595959;
			border-radius: 28rpx;
			display: flex;
			//position: relative;
			.icon {
				width: 50rpx;
				height: 46rpx;
				margin-top: 3rpx;
	
				image {
					width: 100%;
					height: 100%;
				}
			}
	
			.search-input {
				flex: 1;
				height: 100%;
				color: #999;
				position: relative;
			}
			.clear-icon {
				width: 44rpx;
				height: 44rpx;
				color: #fff;
				border-radius: 50%;
				line-height: 40rpx;
				text-align: center;
				margin-top: 4rpx;
				background-color: #c8c9cc;
			}
		}
	
		.pop {
			position: absolute;
			right: 40rpx;
		}
	}
</style>
